package com.ttc.group2.videochat.helper;

import java.util.Collection;

import android.content.Context;
import android.os.Bundle;

import com.quickblox.core.exception.QBResponseException;
import com.quickblox.core.request.QBPagedRequestBuilder;
import com.quickblox.users.QBUsers;
import com.quickblox.users.model.QBUser;
import com.ttc.group2.videochat.model.User;
import com.ttc.group2.videochat.utils.Const;
import com.ttc.group2.videochat.utils.UserUtils;

public class QBRestHelper extends BaseHelper {

	public QBRestHelper(Context context) {
		super(context);
	}

	public User loadUser(int userId) {
		User resultUser = null;

		try {
			QBUser user = QBUsers.getUser(userId);
			resultUser = UserUtils.createUser(user);
		} catch (QBResponseException e) {
			// user not found
		}

		return resultUser;
	}

	public Collection<User> loadUsers(Collection<Integer> usersIdsList)
			throws QBResponseException {
		QBPagedRequestBuilder requestBuilder = new QBPagedRequestBuilder();
		requestBuilder.setPage(Const.FL_FRIENDS_PAGE_NUM);
		requestBuilder.setPerPage(Const.FL_FRIENDS_PER_PAGE);
		Collection<QBUser> usersList = QBUsers.getUsersByIDs(usersIdsList,
				requestBuilder, new Bundle());
		Collection<User> usersListResult = UserUtils.createUsersList(usersList);
		return usersListResult;
	}
}